/*
 * Drunk Js
 * Author    :   Drunk
 * Website   :   http://drunkce.com,  http://idrunk.net
 */


(function(){
// yeah printer
var p = {
    init : function(){
        var body = $('body');
        p.wrap = $('.printer-ctrl-wrap');
        if(!p.wrap.length) p.wrap = $('<div class="printer-ctrl-wrap"></div>').appendTo(body);
        p.btn = p.wrap.find('.printer-ctrl-btn');
        if(!p.btn.length) p.btn = $('<input type="button" class="printer-ctrl-btn" value="打印" />').appendTo(p.wrap);
        p.btn.bind('click', p.print);
        p.wrap.bind('mouseover', function(){ return false; });
        body.bind('mouseover', function(){
            p.wrap.fadeIn();
        })
    },
    print : function(){
        p.wrap.fadeOut( function(){
            try{
                jatoolsPrinter.printPreview({documents:document,copyrights: '杰创软件拥有版权  www.jatools.com'});
            }catch(e){
                window.print();
            }
        });
    },
    print_list : function(cnf){
        if(!cnf.link) return false;
        var c = {
            title : '打印记录',
            link : ''
        };
        if(cnf.title) c.title = cnf.title;
        if(cnf.link) c.link = cnf.link;
        //弹出框组件  [http://layer.layui.com/api.html]
        top.layer.open({
            type: 2,
            title: c.title,
            maxmin: true,
            shadeClose: false, //点击遮罩关闭层
            area : ['500px' , '400px'],
            content: c.link,
            end : function(){
               
            }
        });
    }
};

$(function(){ p.init(); });
window.DP = p;
})();